/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.ferfalk.simplesearchview;

import ohos.utils.Parcel;
import ohos.utils.Sequenceable;

import java.io.Serializable;

/**
 * SavedState for SimpleSearchView
 *
 * @since 2021-04-16
 */
public class SavedState implements Sequenceable, Serializable {
    /**
     * PRODUCER
     *
     */
    public static final Producer PRODUCER = in -> {
        // Initialize an instance first, then do customized unmarshlling.
        SavedState instance = new SavedState();
        instance.unmarshalling(in);
        return instance;
    };
    private String query;
    private boolean isSearchOpen;
    private int animationDuration;
    private String voiceSearchPrompt;
    private boolean keepQuery;
    private int selectedTabIndex;
    private boolean isMenuOpen;
    private int menuY;

    public String getQuery() {
        return query;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public boolean isSearchOpen() {
        return isSearchOpen;
    }

    public void setSearchOpen(boolean searchOpen) {
        isSearchOpen = searchOpen;
    }

    public int getAnimationDuration() {
        return animationDuration;
    }

    public void setAnimationDuration(int animationDuration) {
        this.animationDuration = animationDuration;
    }

    public String getVoiceSearchPrompt() {
        return voiceSearchPrompt;
    }

    public void setVoiceSearchPrompt(String voiceSearchPrompt) {
        this.voiceSearchPrompt = voiceSearchPrompt;
    }

    public boolean isKeepQuery() {
        return keepQuery;
    }

    public void setKeepQuery(boolean keepQuery) {
        this.keepQuery = keepQuery;
    }

    public int getSelectedTabIndex() {
        return selectedTabIndex;
    }

    public void setSelectedTabIndex(int selectedTabIndex) {
        this.selectedTabIndex = selectedTabIndex;
    }

    public boolean isMenuOpen() {
        return isMenuOpen;
    }

    public void setMenuOpen(boolean isMenuOpened) {
        this.isMenuOpen = isMenuOpened;
    }

    public int getMenuY() {
        return menuY;
    }

    public void setMenuY(int menuY) {
        this.menuY = menuY;
    }

    @Override
    public boolean marshalling(Parcel out) {
        return out.writeString(query)
                && out.writeBoolean(isSearchOpen)
                && out.writeInt(animationDuration)
                && out.writeString(voiceSearchPrompt)
                && out.writeBoolean(keepQuery)
                && out.writeInt(selectedTabIndex)
                && out.writeBoolean(isMenuOpen)
                && out.writeInt(menuY);
    }

    @Override
    public boolean unmarshalling(Parcel in) {
        this.query = in.readString();
        this.isSearchOpen = in.readBoolean();
        this.animationDuration = in.readInt();
        this.voiceSearchPrompt = in.readString();
        this.keepQuery = in.readBoolean();
        this.selectedTabIndex = in.readInt();
        this.isMenuOpen = in.readBoolean();
        this.menuY = in.readInt();
        return true;
    }

    @Override
    public String toString() {
        return "SavedState{"
                + "query='" + query + '\''
                + ", isSearchOpen=" + isSearchOpen
                + ", animationDuration=" + animationDuration
                + ", voiceSearchPrompt='" + voiceSearchPrompt
                + '\'' + ", keepQuery=" + keepQuery
                + ", selectedTabIndex=" + selectedTabIndex
                + ", isMenuOpen=" + isMenuOpen
                + ", menuY=" + menuY
                + '}';
    }
}
